package team.nmsg.auto;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;

import com.alibaba.fastjson.JSONObject;

import team.nmsg.ge.system.interf.ISysBean;

@Entity
@Table( indexes = { @Index(name = "dev_sn_index", columnList = "devSn") }   )
public class TestLog implements ISysBean{
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long logId;
	
	private Long timeStamp;
	
	private String user;
	

	private String testtype; // 机框基测 / 主控基测 / 线卡基测 / 电源测试
	
	private String res;  //成功 / 失败
	
	private String descr;  //描述 
	
	@Column(length=128)
	private String devSn;  //设备SN   
	
	private int costTime;//耗时  秒
	
	private String groupID; //测试组ID
	
	private int type; //1 基测 2 复测
	
	public Long getLogId() {
		return logId;
	}


	public void setLogId(Long logId) {
		this.logId = logId;
	}


	public Long getTimeStamp() {
		return timeStamp;
	}


	public void setTimeStamp(Long timeStamp) {
		this.timeStamp = timeStamp;
	}


	public String getUser() {
		return user;
	}


	public void setUser(String user) {
		this.user = user;
	}


	public String getTesttype() {
		return testtype;
	}


	public void setTesttype(String testtype) {
		this.testtype = testtype;
	}


	public String getRes() {
		return res;
	}


	public void setRes(String res) {
		this.res = res;
	}


	public String getDescr() {
		return descr;
	}


	public void setDescr(String descr) {
		this.descr = descr;
	}


	public String getDevSn() {
		return devSn;
	}


	public void setDevSn(String devSn) {
		this.devSn = devSn;
	}


	public int getCostTime() {
		return costTime;
	}


	public void setCostTime(int costTime) {
		this.costTime = costTime;
	}


	public String getGroupID() {
		return groupID;
	}


	public void setGroupID(String groupID) {
		this.groupID = groupID;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	@Override
	public JSONObject toJson() {
		JSONObject json = (JSONObject) JSONObject.toJSON(this);
		json.put("logId", logId);
		json.put("timeStamp", formatDate(timeStamp));
		json.put("user", user);
		json.put("testtype", testtype);
		json.put("res", res);
		json.put("descr", descr);
		json.put("devSn", devSn);
		json.put("costTime", costTime);
		json.put("groupID", groupID);
		json.put("type", type);
		return json;
	}
	
	public String formatDate(Long timestamp){
		
		if( timestamp ==null ){
			return "";
		}
		
		Date date = new Date(timestamp);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}
	
	
}
